package config;

import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;


public class SysConfig {
	private static String propLocation="/config/config.properties";//属性文件位置
	private static Properties property;
	static{
		init();
	}
	public static void init(){
		if(propLocation != null){
			if(propLocation.indexOf(",") != -1){
				String[] locations = propLocation.split(",");
				int size = locations.length;
				for(int i=0; i<size; i++){
					String location = locations[i];
					initSinglePropertyFile(location);
				}
			}else{
				initSinglePropertyFile(propLocation);
			}
		}
	}
	public static void initSinglePropertyFile(String location){
		if(location.trim().endsWith(".properties")){
			InputStream in = SysConfig.class.getClassLoader().getResourceAsStream(location);
			if(property == null)
				property = new Properties();
			try {
				property.load(in);
			} catch (IOException e) {
				e.printStackTrace();
			} 
		}
	}
	public static String getProperty(String propname){
		return property.getProperty(propname);
	}
}
